"""
推导式: 列表, 字典, 元组, set
列表: [计算公式 for i in lst if判断]
字典: {计算公式 for k,v in dct.items() if判断}
字典: {计算公式 for i in dct if判断}
set: {计算公式 for i in set1 if判断}
"""
# 列表

"""生成1-50之间偶数平方的列表"""

# 方式一
lst1 = []
for i in range(1, 51):
    lst1.append(i)
print(lst1)

# 方式二
lst2 = [i for i in range(1, 51)]
print(lst2)

# 方式三
lst3 = [i + 1 for i in range(50)]
print(lst3)

"""生成1-10之间偶数平方的列表"""
lst = [i * i for i in range(10) if i % 2 == 0]
print(lst)

ls2 = [i ** 2 for i in range(0, 10, 2)]
print(ls2)

"""生成10个元素的列表 元素都 是'666'"""

lst = ['666' for i in range(10)]
print(lst)

"""过滤列表中姓名长度小于4的"""
lst = ["zhangsan", "lisi", "wangwu"]
lst2 = [name for name in lst if len(name) <= 4]
print(lst2)

# 字典

# {"1": 1, "2": 4}
dct = {str(i): i * i for i in range(1, 6)}
print(dct)

# {'a': 'A', 'b': 'B'}
# 方式一
dct = {'A': 'a', 'B': 'b'}
dct2 = {dct[key]: key for key in dct}
print(dct2)

# 方式二
dct3 = {value: key for key, value in dct.items()}
print(dct3)
